<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >添加</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="pathDetailList">
        <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="地点管理" align="center" prop="placeId" >
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.placeId" clearable placeholder="请选择地点管理">
                      <el-option
                        v-for="dict in placeOptions"
                        :key="dict.id"
                        :label="dict.placeName"
                        :value="dict.id"
                      ></el-option>
                    </el-select>
                  </template>
            </el-table-column>

            <el-table-column label="巡检日期" align="center" prop="patrolDate" >
            <template slot-scope="scope">
              <el-select v-model="scope.row.patrolDate" clearable placeholder="请选择巡检日期">
                  <el-option
                    v-for="dict in dict.inspection_cycle"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="dict.dictValue"
                  ></el-option>
              </el-select>
            </template>
            </el-table-column>
<!--            <el-table-column label="巡检时间" align="center" prop="patrolTime" >
              <template slot-scope="scope">
                <el-input v-model="scope.row.patrolTime" placeholder="请输入巡检时间" />
              </template>
            </el-table-column>-->
            <el-table-column label="备注" align="center" prop="remark">
              <template slot-scope="scope">
                <el-input v-model="scope.row.remark" placeholder="请输入备注" />
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['waitress:PathDetail:remove']"
              >移除</el-button>
            </template>
          </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>

import { listMixin } from "@/utils/mixins/listMixin";
import { listPathDetail} from "@/api/waitress/PathDetail";
import { listPlace} from "@/api/waitress/place";
export default {
  name: "PathDetailA",
  mixins:[ listMixin ],
  dicts: [   'inspection_cycle',   ],
  props: {
    communityId: {
      type: String,
      default: "",
    },
    pathId:{
      type: String,
      default: "",
    }
  },
  data() {
    return {
      // 路线明细表格数据
      pathDetailList: [],
      placeOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pathId: null,
        placeId: null,
        patrolDate: null,
        patrolTime: null,
      },
    };
  },
  watch:{
    'this.communityId'(v){
     this.getParkId();
    }
  },
  created() {
    this.getList();
    this.getParkId();
  },
  methods: {
    getParkId(){
      //根据小区id以及地点状态查询
      listPlace({'communityId':this.communityId || -1,'placeState':'10'}).then(res =>{
        this.placeOptions = res.rows;
      })
    },
    /** 查询路线明细列表 */
    getList() {
      this.loading = true;
      this.queryParams.pathId = this.pathId||-1;
      listPathDetail(this.queryParams).then(response => {
        this.pathDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getDetailList(){
      return this.pathDetailList;
    },
    /** 新增按钮操作 */
    handleAdd() {
        this.pathDetailList.push({
          id:null,
          pathId: null,
          placeId: null,
          patrolDate: null,
          patrolTime: null,
        })
    },
    /** 删除按钮操作 */
    handleDelete(row,index) {
      this.pathDetailList.splice(index,1);
    },
  }
};
</script>
